home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.2 KB | 65 lines | [TEXT/CWIE] |
- // Directory.cp
-
- #ifndef Directory_h
- #include "Directory.h"
- #endif
- #ifndef CatInfo_h
- #include "CatInfo.h"
- #endif
- #ifndef NotADirectoryError_h
- #include "NotADirectoryError.h"
- #endif
- #ifndef DirectoryNotFoundError_h
- #include "DirectoryNotFoundError.h"
- #endif
-
- void Directory::Up()
- {
- Assert( !IsRoot() );
- CatInfo info( *this );
- id = info.Location().ParentID();
- }
-
- void Directory::Down( ConstPString name )
- {
- CatInfo info( *this, name );
-
- if ( !info.IsDirectory() )
- throw NotADirectoryError( noErr );
-
- volume = info.Location().Volume();
- id = info.Directory().ID();
- }
-
- Directory Directory::Parent() const
- {
- Assert( !IsRoot() );
- CatInfo info( *this );
- return info.Location().Parent();
- }
-
- Directory Directory::Find( VolumeID volume,
- OSType folder,
- bool creating )
- {
- int16 volumeFound;
- int32 directoryFound;
- OSErr error = FindFolder( volume.RefNum(),
- folder,
- creating,
- &volumeFound,
- &directoryFound );
-
- switch ( error )
- {
- case fnfErr: throw DirectoryNotFoundError( error );
- case dupFNErr: throw NotADirectoryError( error );
- }
-
- if ( error != noErr )
- throw FileError( error );
-
- return Directory( VolumeID::Make( volumeFound ),
- DirectoryID::Make( directoryFound ) );
- }
-